var app = getApp()
Page({
  data: {
    current: 'tab1',
    current_scroll: 'tab1',
    tab1: true,
    tab2: false,
    user_id: '',
    orders:[]
  },

  onLoad: function () {
    this.setData({
      user_id: wx.getStorageSync('uid')
    })
    this.orders(this.data.user_id , 999)
  },

  handleChange({ detail }) {
    var index = detail.key
    this.setData({
      current: detail.key
    });
    if (index == 'tab1') {
      this.setData({
        tab1: true,
        tab2: false,
        tab3: false,
        tab4: false
      })
      this.orders(this.data.user_id, 999)
    }
    else if (index == 'tab2') {
      this.setData({
        tab1: false,
        tab2: true,
        tab3: false,
        tab4: false
      })
      this.orders(this.data.user_id, 0)
    }
    else if (index == 'tab3') {
      this.setData({
        tab1: false,
        tab2: false,
        tab3: true,
        tab4: false
      })
      this.orders(this.data.user_id, 1)
    }
    else if (index == 'tab4') {
      this.setData({
        tab1: false,
        tab2: false,
        tab3: false,
        tab4: true
      })
      this.orders(this.data.user_id, 2)
    }        
  },

  orders(uid, status){
    let that = this
    wx.request({
      url: app.url + 'weiapp/api/getOrders',
      data:{
        uid:uid,
        status:status
      },
      success:function(res){
        console.log(res.data.data)
        that.setData({
          orders:res.data.data
        })
      }
    })
  }

});